

package service;

import beans.User;
import java.sql.ResultSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import jdbc.MyJdbc;


public class AddUserService {
    User user = null;
    
    public AddUserService() {
    }
    

    public boolean add(User user) {
        try {
            String sql = "select * from Student where ID=?";
            String updateSql = "insert into Student value(?,?,?,?,?,?,?,?,?,?,?)";
            MyJdbc jdbc = new MyJdbc();
            jdbc.getConnection();
            ResultSet res = jdbc.query(sql, user.getId());
           // System.out.println(user.getId());
            if(res.next()) {
                return false;
            } else {
                jdbc.update(updateSql,user.getId(),user.getPasswords(),user.getName(),user.getSex(),0,user.getMajor(),user.getClas(),user.getTelephone(),user.getQQ(),user.getEmail(),user.getAdd());
                return true;
            }
            
        } catch (Exception ex) {
            Logger.getLogger(AddUserService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
        
    }
}
